<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('图片库')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="role-form">
                <input type="hidden" id="priMesId" name="priMesId" th:value="${priMesId}">
                <div class="select-list">
                    <ul>
                        <li>
                            图片名称：<input type="text" name="phoGalImg"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-warning" onclick="closeItem()">
                <i class="fa fa-reply-all"></i> 关闭
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var removeFlag = [[${@permission.hasPermi('system:role:remove')}]];
    var datas = [[${@dict.getType('sys_normal_disable')}]];
    var prefix = ctx + "datum/show";

    var perImg = ctx + "img/";

    $(function() {
        var options = {
            url: prefix + "/photoList",
            importUrl: prefix + "/importData",
            importTemplateUrl: prefix + "/importTemplate",
            sortName: "phoGalSort",
            modalName: "图库",
            columns: [{
                checkbox: true
            },
                {
                    field: 'phoGalId',
                    title: '图片ID',
                },
                {
                    field: 'phoGalImg',
                    title: '图片信息',
                    formatter: function(value, row, index) {
                        // 图片预览（注意：如存储在本地直接获取数据库路径，如有配置context-path需要使用ctx+路径）
                        // 如：/profile/upload/2019/08/08/3b7a839aced67397bac694d77611ce72.png
                        return $.table.imageView(perImg + row.phoGalImg);
                    }
                },
                {
                    field: 'phoGalSort',
                    title: '排序值',
                    sortable: true
                },
                {
                    field: 'phoGalShow',
                    title: '图片是否显示',
                    formatter: function(value, row, index) {
                            return phoGalShowTools(row);
                    }
                }]
        };
        $.table.init(options);
    });

    /* 图片是否显示 */
    function phoGalShowTools(row) {
        if (row.phoGalShow == 1) {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="enable(\'' + row.phoGalId + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="disable(\'' + row.phoGalId + '\')"></i> ';
        }
    }

    /* 图片不显示 */
    function disable(phoGalId) {
        $.modal.confirm("确认要显示图片吗？", function() {
            $.operate.post(prefix + "/changePhoGalShow", { "phoGalId": phoGalId, "phoGalShow": 1 });
        })
    }

    /* 图片显示 */
    function enable(phoGalId) {
        $.modal.confirm("确认要关闭图片显示吗？", function() {
            $.operate.post(prefix + "/changePhoGalShow", { "phoGalId": phoGalId, "phoGalShow": 0 });
        })
    }

</script>
</body>
</html>